package com.gilight.base.controller.uiapp;

import com.gilight.base.base.ResultEntity;
import com.gilight.base.base.exception.ServiceException;
import com.gilight.base.uiapp.product.ProductService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author liken
 * 商品管理控制类
 */
@RestController
@RequestMapping("/web/app-product")
public class AppProductController {

    @Autowired
    private ProductService productService;


    /**
     *
     * @param pageNo
     * @param pageSize
     * @param categoryId
     * @param orderBy
     * @param isAsc
     * @param title
     * @return
     */
    @ApiOperation(value = "商品分类大树")
    @RequestMapping(value = "/get-product-page", method = {RequestMethod.GET})
    public ResultEntity getProductPage(Integer pageNo,
                                       Integer pageSize,
                                       Long categoryId,
                                       String orderBy,
                                       Boolean isAsc,
                                       String title,
                                       Long zzjgId,
                                       Long brandId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            if(zzjgId == null){
                zzjgId = 1L;
            }
            if(brandId == null){
                brandId = 1L;
            }
            resultEntity.setData(productService.getProductPage(pageNo,pageSize,categoryId,orderBy,isAsc,title,zzjgId));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }

    @ApiOperation(value = "创建")
    @RequestMapping(value = "/create")
    public ResultEntity getProduct(Long spuId,
                                   Integer isBaiHuo,
                                   Long zzjgId) {
        ResultEntity resultEntity = new ResultEntity();
        if(zzjgId == null){
            zzjgId = 1L;
        }
        try {
            resultEntity.setData(productService.getProduct(spuId,isBaiHuo, zzjgId));
        } catch (ServiceException e) {
            e.printStackTrace();
        };
        return resultEntity;
    }

    @ApiOperation(value = "获取商品详情")
    @RequestMapping(value = "/detail")
    public ResultEntity getProductDetail(Long spuId,
                                   Integer isBaiHuo,
                                         Long zzjgId) throws ServiceException {
        ResultEntity resultEntity = new ResultEntity();
        if(zzjgId == null){
            zzjgId = 1L;
        }
            resultEntity.setData(productService.getProduct(spuId,isBaiHuo,zzjgId));

        return resultEntity;
    }
}
